package org.sys.transporttrainsys.controller;

import org.sys.transporttrainsys.entity.DocumentVideoType;
import org.sys.transporttrainsys.service.DocumentVideoTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:5173")
@RequestMapping("/api/document-video-types")
public class DocumentVideoTypeController {

    @Autowired
    private DocumentVideoTypeService documentVideoTypeService;

    @GetMapping
    public List<DocumentVideoType> getAllDocumentVideoTypes() {
        return documentVideoTypeService.getAllDocumentVideoTypes();
    }

    @GetMapping("/{id}")
    public ResponseEntity<DocumentVideoType> getDocumentVideoTypeById(@PathVariable Long id) {
        DocumentVideoType documentVideoType = documentVideoTypeService.getDocumentVideoTypeById(id);
        return ResponseEntity.ok(documentVideoType);
    }

    @PostMapping
    public DocumentVideoType createDocumentVideoType(@RequestBody DocumentVideoType documentVideoType) {
        return documentVideoTypeService.createDocumentVideoType(documentVideoType);
    }

    @PutMapping("/{id}")
    public ResponseEntity<DocumentVideoType> updateDocumentVideoType(@PathVariable Long id, @RequestBody DocumentVideoType documentVideoType) {
        DocumentVideoType updatedType = documentVideoTypeService.updateDocumentVideoType(id, documentVideoType);
        return ResponseEntity.ok(updatedType);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteDocumentVideoType(@PathVariable Long id) {
        documentVideoTypeService.deleteDocumentVideoType(id);
        return ResponseEntity.noContent().build();
    }

    @GetMapping("/search")
    public List<DocumentVideoType> searchByTypeName(@RequestParam String name) {
        return documentVideoTypeService.searchByTypeName(name);
    }
}